<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>25.使用正则去掉字符串左右的空格</title>
        <script>
            var str = '  allen    ';
            var re = /^\s+|\s+$/g;
            alert('(' + trim(str) + ')');

            // 封装一个去掉空格的方法
            function trim (str) {
                return str.replace(re, '');
            }
        </script>
    </head>
    <body>

    </body>
</html>
